[mirrors]
ftp://sourceware.org/pub/binutils/snapshots/binutils-2.24.90.tar.bz2
http://www.mirrorservice.org/sites/sourceware.org/pub/binutils/snapshots/binutils-2.24.90.tar.bz2

[vars]
filesize=23659627
sha512=dcd93cb314d5c275529c58d134956e48d64860bdd2e58bc94aa339aeba0ee66fbd7423ace1f71eba9905fa5b05db922c2242f585c8eef0247c4fa5fda56367af
desc="provides linker, assembler and other utils to handle object files"

[deps.stage0]
stage0-musl

[build]
patch -p1 < "$K"/binutils-arm.patch

"$K"/libibertyfix libiberty

[ "$STAGE" = "0" ] && CC="$butch_root_dir"/bin/musl-gcc
machine=
if [ -n "$CROSS_COMPILE" ] ; then
        machine=$($CC -dumpmachine)
        xconfflags="--host=$machine --target=$machine"
        export GCC_FOR_TARGET="$CC"
fi

config_arch_flags=
if [ "$A" = "powerpc" ] ; then
        config_arch_flags="--enable-secureplt"
fi
static_ldflags=-Wl,-static
static_ccflags=-static
config_lto_flags=
if [ "$BINUTILS_DYNAMIC" = 1 ] ; then
	static_ldflags=
	static_ccflags=
	config_lto_flags=--enable-lto
fi
LDFLAGS="$static_ldflags $optldflags" \
CC="$CC $static_ccflags" \
CFLAGS="-D_GNU_SOURCE -D_LARGEFILE64_SOURCE $optcflags" \
./configure -C --prefix="$butch_prefix" $xconfflags \
  --disable-nls --disable-werror \
  --enable-initfini-array \
  --disable-install-libbfd $config_arch_flags $config_lto_flags

make -j$MAKE_THREADS
# tooldir=/
make DESTDIR=$butch_install_dir install-gas install-ld install-binutils

dest="$butch_install_dir""$butch_prefix"
mkdir -p "$dest"/lib/bfd-plugins
ln -sf "$butch_prefix"/lib/bfd-plugins/liblto_plugin.so \
       "$dest"/lib/bfd-plugins/liblto_plugin.so
rm -f "$dest"/bin/ld
if [ x$A = xpowerpc ] ; then
	cat << EOF > "$dest"/bin/ld
#!/bin/sh
ld.bfd --secure-plt \$@
EOF
	chmod +x "$dest"/bin/ld
else
	ln -sf ld.bfd "$dest"/bin/ld
fi
